package com.kld.test;

import android.os.SystemClock;

import androidx.annotation.Nullable;

import java.io.IOException;
import java.io.InputStream;

import tp.xmaihh.serialport.stick.AbsStickPackageHelper;

public class CustomStickPackageHelper implements AbsStickPackageHelper {
    @Override
    public byte[] execute(InputStream is) {
        byte[] buffer = readOneTime(is);
        if (buffer != null) {

            return buffer;
        }

        return null;
    }

    @Nullable
    private static byte[] readOneTime(InputStream is) {
        try {
            int available = is.available();
            if (available > 0) {
                byte[] buffer = new byte[2048];
                int size = is.read(buffer);
                if (size > 0) {
                    return buffer;
                }
            } else {
                SystemClock.sleep(500L);
            }
        } catch (IOException var5) {
            var5.printStackTrace();
        }
        return null;
    }
}
